/* This file is part of xREL
 *
 * Copyright (C) 2012 Timo Zimmermann <xrel@timozimmermann.de>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

import QtQuick 1.1
import com.nokia.meego 1.0
import com.xrel 1.0

import "delegates"
import "components"

Page {
    id: root

    property string name: "EntertainmentPage"
    property string id

    tools: mainToolBar

    XmlListModel {
        id: xmlUpcomingModel
        source: "http://api.xrel.to/api/calendar/upcoming.xml"
        query: "/upcoming_titles/ext_info"

        XmlRole { name: "type"; query: "type/string()" }
        XmlRole { name: "id"; query: "id/string()" }
        XmlRole { name: "title"; query: "title/string()" }
        XmlRole { name: "link_href"; query: "link_href/string()" }
        XmlRole { name: "genre"; query: "genre/string()" }
        XmlRole { name: "cover_url"; query: "cover_url/string()" }
        XmlRole { name: "alt_title"; query: "alt_title/string()" }
        XmlRole { name: "releases_count"; query: "count(releases/release)" }
    }

    PageBackground { }

    PageHeader {
        id: pageHeader
        anchors.top: parent.top
        text: qsTr("Entertainment")
    }

    ListView {
        id: listView
        anchors.top: pageHeader.bottom
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        anchors.margins: 0
        cacheBuffer: 25*80
        opacity: screen.currentOrientation  === Screen.Portrait

        spacing: 6
        clip: true

        delegate: EntertainmentDelegate { }
        model: xmlUpcomingModel

        XmlViewBusyIndicator { }

        function showProductInfo(id) {
            pageStack.push(Qt.resolvedUrl("ProductInfoPage.qml"), { id: id })
        }
    }

    PathView {
        id: listPathView
        anchors.top: pageHeader.bottom
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        anchors.margins: 0
        //offset: 200
        pathItemCount: 5
        clip: true
        highlightRangeMode: PathView.ApplyRange

        opacity: screen.currentOrientation  === Screen.Landscape

        delegate: EntertainmentPathDelegate { }
        model: xmlUpcomingModel

        path: Path {
            startX: -listView.width*0; startY: listView.height/2
            PathAttribute { name: "iconScale"; value: 0.2 }
            PathAttribute { name: "iconOpacity"; value: 0.2 }
            PathPercent { value: 0.0 }

            PathLine { x: listView.width*0.5; y: listView.height/2 }
            PathAttribute { name: "iconScale"; value: 1.0 }
            PathAttribute { name: "iconOpacity"; value: 1.0 }
            PathPercent { value: 0.5 }

            PathLine { x: listView.width*1; y: listView.height/2 }
            PathAttribute { name: "iconScale"; value: 0.2 }
            PathAttribute { name: "iconOpacity"; value: 0.2 }
            PathPercent { value: 1.0 }
        }

        XmlViewBusyIndicator { }

        function showProductInfo(id) {
            pageStack.push(Qt.resolvedUrl("ProductInfoPage.qml"), { id: id })
        }
    }
}
